package com.wonders.common.web.captcha.util;

import org.apache.commons.lang3.StringUtils;

import com.wonders.common.web.captcha.controller.CaptchaController;
import com.wonders.framework.util.web.RequestUtil;

/**
 * 验证码工具
 * 
 * @author WuBin
 * 
 */
public class CaptchaUtil {

	/**
	 * 校验验证码
	 * 
	 * @param key
	 *            键
	 * @param code
	 *            值
	 * @return 是否正确
	 */
	public static boolean validate(String key, String code) {
		if (StringUtils.isEmpty(key) || StringUtils.isEmpty(code)) {
			return false;
		}
		String captcha = RequestUtil.getSessionAttr(
				StringUtils.join(CaptchaController.PREFIX, key), String.class);
		if (!code.equals(captcha)) {
			return false;
		}
		return true;
	}

}
